package com.geekstudy.controller;

import com.geekstudy.bean.DemoBigDecimalBean;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import java.math.BigDecimal;
import java.util.LinkedHashMap;
import java.util.Map;
import java.util.UUID;

@RestController
public class HelloDemoController {

    final Logger logger = LoggerFactory.getLogger(HelloDemoController.class);

    @RequestMapping(path = "/hello/demo")
    public Map<String, String> helloDemo(@RequestParam(name = "name") String name) {
        logger.info("helloDemo name:{} ", name);
        Map<String, String> resultMap = new LinkedHashMap<>();
        resultMap.put("name", name);
        resultMap.put("requestId", UUID.randomUUID().toString());

        return resultMap;
    }

    // http://127.0.0.1:9001/hello/demo/bigDecimal
    @RequestMapping(path = "/hello/demo/bigDecimal")
    public Map<String, DemoBigDecimalBean> demoBigDecimal() {
        Map<String, DemoBigDecimalBean> demoMap = new LinkedHashMap<>();

        DemoBigDecimalBean demo = new DemoBigDecimalBean();
        demo.setDemo1(new BigDecimal("123456789123456789123"));
        demo.setDemo1ToString(demo.getDemo1().toString());
        demo.setDemo1StringOf(String.valueOf(demo.getDemo1()));

        demo.setDemo2(new BigDecimal("123456789123456789123456789.999"));
        demo.setDemo3(new BigDecimal("987654321987654321987654321.999"));
        demo.setDemo4(new BigDecimal("22233344455566677788899900011122233"));
        demoMap.put("case1", demo);
        demoMap.put("case2", demo);

        return demoMap;
    }
}
